#include "CSetTriPrismParamsCommand.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "IMeshSceneNode.h"
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "CSceneObject.h"

extern CGlobals* g;
extern CUserInterface* ui;
extern CLevelEditor* editor;

CSetTriPrismParamsCommand::CSetTriPrismParamsCommand (int id, f32 oldSize, f32 newSize, f32 oldAngle, f32 newAngle)
{
	m_id = id;
	m_oldSize = oldSize;
	m_newSize = newSize;
	m_oldAngle = oldAngle;
	m_newAngle = newAngle;
	stringw name = editor->getSceneObjectFromID(id)->m_UserData->getAttributeAsStringW("Name");
	setDescription(stringw(L"modify ") + name + L"(" + stringw(id) + L")");
}

void CSetTriPrismParamsCommand::redo ()
{
	ISceneNode* node = g->sceneManager->getSceneNodeFromId(m_id);
	editor->updateTriPrismMeshWithParams(((IMeshSceneNode*)node)->getMesh() , m_newSize, m_newAngle);

	CSceneObject* scObj = editor->getSceneObjectFromID(m_id);
	scObj->m_UserData->setAttribute("Size", m_newSize);
	scObj->m_UserData->setAttribute("Angle", m_newAngle);
}

void CSetTriPrismParamsCommand::undo ()
{
	ISceneNode* node = g->sceneManager->getSceneNodeFromId(m_id);
	editor->updateTriPrismMeshWithParams( ((IMeshSceneNode*)node)->getMesh(), m_oldSize, m_oldAngle );

	CSceneObject* scObj = editor->getSceneObjectFromID(m_id);
	scObj->m_UserData->setAttribute("Size" , m_oldSize);
	scObj->m_UserData->setAttribute("Angle" , m_oldAngle);
}
